package com.eol.entity.dto.pay;

import cn.hutool.core.codec.Base64;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.annotations.ApiModel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.math.BigDecimal;

/**
 * Created with IntelliJ IDEA.
 * User: liulinhui
 * Date: 2020/5/25
 * Time: 3:12 PM
 * Description: PayInputDto
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
@ApiModel("支付参数")
public class PayInputDto implements Serializable {
    private static final long serialVersionUID = 1L;

    //订单ID
    private String orderId;
    //订单ID
    private String openId;
    //订单金额 单位：元
    private BigDecimal money;
    //订单描述
    private String des;
    //支付渠道类型
    private String channelType;
    //支付渠道
    private String channelName;
    //商品类型 1:课程 2：会员
    private Integer type;
    //支付成功后跳转URL
    private String returnUrl;

    public String toBase64() {
        JSONObject jsonObject = (JSONObject) JSONObject.toJSON(this);
        return Base64.encode(jsonObject.toJSONString(), "utf-8");
    }

    public static PayInputDto decode(String codeStr) {
        String decode = Base64.decodeStr(codeStr);
        return JSONObject.toJavaObject((JSONObject) JSON.parse(decode), PayInputDto.class);
    }
}
